from rest_framework.response import Response
from rest_framework.generics import GenericAPIView
from rest_framework.mixins import ListModelMixin, CreateModelMixin, RetrieveModelMixin, UpdateModelMixin
import json
from .serializer import BookSerializer
from books.models import BookInfo


class Books(GenericAPIView, ListModelMixin, CreateModelMixin):
    serializer_class = BookSerializer
    queryset = BookInfo.objects.all()

    def get(self, request):
        return self.list(request)

    def post(self, request):
        return self.create(request)


class Book(GenericAPIView, RetrieveModelMixin, UpdateModelMixin):
    serializer_class = BookSerializer
    queryset = BookInfo.objects.all()

    def get(self, request, pk):
        return self.retrieve(request)

    def put(self, request, pk):
        return self.update(request)
